-
Notifications
You must be signed in to change notification settings - Fork 245
fix Problem with displaying whitespace chars literals #1975 #1976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes the display of whitespace and control characters in bytes literals by properly escaping them instead of rendering them as raw characters. Previously, control characters like tabs and newlines would be displayed literally, causing readability issues.
Key Changes:
- Replaced Unicode character conversion with explicit byte-level escape handling for bytes literals
- Added proper escaping for common control characters (
\t,\n,\r) and special characters (\\,\') - Added regression test to verify whitespace and control bytes are displayed correctly
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/pyrefly_types/src/literal.rs |
Removed unused char import and replaced char::from_u32 conversion with pattern matching to properly escape control characters, quotes, and backslashes in bytes literals |
crates/pyrefly_types/src/display.rs |
Added test case verifying that whitespace and control characters in bytes literals are properly escaped in display output |
After thoroughly reviewing the changes, I found no issues with this PR. The implementation correctly:
- Escapes common control characters (
\t,\n,\r) - Escapes backslashes and single quotes (necessary for single-quoted bytes literals)
- Renders printable ASCII characters (space through tilde) as-is
- Escapes all other bytes using hex notation (
\xNN) - Removes the now-unused
charimport - Includes an appropriate regression test
The changes align with Python's bytes literal syntax and fix the reported issue with whitespace character display.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@asukaminato0721 Would it be better to reuse the code for string literals? pyrefly/crates/pyrefly_types/src/literal.rs Lines 180 to 209 in 51ea20d
|
|
it's a bit different vs the match arm is char vs b' ' |
stroxler
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review automatically exported from Phabricator review in Meta.
Summary
Fixes #1975
Adjusted byte literal display to escape control characters, quotes, and backslashes so defaults render as readable escapes instead of raw whitespace, and added a regression test for whitespace/control bytes.
Test Plan
add a literal-bytes display assertion covering whitespace/control bytes.